<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <div></div>
    <script>
        var user = '{"id":1001,"age":20,"address":[{"hometown":"南京"},{"hometown":"北京"},{"hometown":"上海"}]}';
        // console.log(user);
        // console.log(typeof user);//string

        var obj = JSON.parse(user);//将字符串转换为对象
        var div = document.querySelector("div");//获取div的DOM对象
        for (var i = 0; i < obj.address.length; i++) {
            var p=document.createElement("p");
            p.innerHTML = obj.address[i].hometown;
            div.appendChild(p);
        }
    </script>
</body>

</html>